﻿/*
 * Created by SharpDevelop.
 * User: BadaninMV
 * Date: 31.01.2015
 * Time: 14:03
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Region
{
  class DirReestrAuto : DirItem
  {
      Engine m_engine;
      Dictionary<String, Object> m_InitWheres;
      AutoList m_List;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return false; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void Open(DirItem Item)
      {
          Int32 ID = (Int32)Item.getData(0, "ID");
          var F = new Forms.RasporForm(m_engine, ID);
          F.ShowDialog();
      }
      public override void Filter()
      {

          m_List.clearWhere();
          foreach (String Pole in m_Params.getParams())
              m_List.setWhere(Pole, m_Params.getPole(Pole));
          if (m_Wheres!=null)
              foreach (var Wheres in m_Wheres)
                  m_List.setWhere(Wheres.Key, Wheres.Value);
          m_List.Filter();
          m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
          Int32 Num = m_List.NumLines;
          Clear();
          for (int i = 0; i < Num; i++)
          {
              Region.AutoList.Line line = m_List.getLine(i);
              DirItem R = new DirItem();
 
              
              R.setData(0, "Caption", "");
              R.setData(0, "ID", line.AutoID);
              R.setData(1, "Caption", line.AutoID.ToString());
              R.setData(2, "Caption", line.Day.ToShortDateString());
              R.setData(3, "Caption", line.UserFIO);
              R.setData(4, "Caption", (line.TimeStart/60).ToString()+":"+(line.TimeStart%60<10?"0":"")+(line.TimeStart%60).ToString());
              R.setData(5, "Caption", (line.TimeEnd/60).ToString()+":"+(line.TimeEnd%60<10?"0":"")+(line.TimeEnd%60).ToString());
              Driver driver = m_engine.getDriver(line.DriverID);
              R.setData(6, "Caption", driver.FIO);
              R.setData(7, "Caption", line.Address);
              R.OnOpen += Open;
              Add(R);
          }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 8; }
      public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "№";
                  case 2: return "День";
                  case 3: return "Специалист";
                  case 4: return "с";
                  case 5: return "по";
                  case 6: return "Водитель";
                  case 7: return "Адрес";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 5: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 6: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 7: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  default: return 100;
              }
          return null;
      }
      void OpenReestr(DirItem Item)
      {
      	var form = new Forms.AutoJournal(m_engine);
      	form.ShowDialog();
      	WhereSetup();
        //Filter();
      }
      void WhereSetup()
      {
        if (m_List!=null) return;
        m_List = new AutoList(m_engine);

          m_Params.addParams("Day", EPoleType.Date);
          m_Params.setPole("Day", DateTime.Now.AddDays(1));
          m_Params.setCaption("Day", "Год:");
          


          
          /*m_Params.addParams("AktDateStart", EPoleType.RegionDate);
          m_Params.setPole("AktDateStart",null);          
          m_Params.addParams("AktDateEnd", EPoleType.RegionDate);
          m_Params.setPole("AktDateEnd",null);*/
          
          
          var IspList = m_List.UserList(18);
          IspList[0] = "[Любой]";
          IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
          m_Params.setExProccessor("IspUserID", IspList);
          m_Params.setCaption("IspUserID", "Исполнитель");
          m_Params.addParams("ParentOtdelID", EPoleType.Int32);
          m_Params.setPole("ParentOtdelID", m_engine.CurrentUser.OtdelID);
          m_Params.setEditor("ParentOtdelID", "TreeComboBox");
          m_Params.setExProccessor("ParentOtdelID", m_engine.OtdelsForTree);
          m_Params.setCaption("ParentOtdelID", "Отдел:");

          m_Params.addParams("Page", EPoleType.Int32);
          m_Params.setPole("Page", 1);            
          m_Params.setEditor("Page", "SelectPage");
          m_Params.setCaption("Page", null);
          m_Params.addParams("NumPage", EPoleType.Int32);                        
          m_Params.setPole("NumPage", 1);
          m_Params.setEditor("NumPage", "");
          m_Params.setCaption("NumPage", null);
          m_Params.setExProccessor("Page", new Dictionary<String,String>(){{"Page","Page"}});
          m_Params.addParams("LineInPage", EPoleType.Int32);
          m_Params.setPole("LineInPage", 20);
          m_Params.setCaption("LineInPage", "Выводить по:");
          
          if (m_InitWheres != null)
          {
              m_Wheres = new Dictionary<String, Object>(m_InitWheres);
              String[] P = m_Params.getParams();
              for (Int32 i = 0; i < P.Length; i++)
              {
                  if (m_Wheres.ContainsKey(P[i]))
                  {
                      m_Params.setPole(P[i], m_Wheres[P[i]]);
                      m_Wheres.Remove(P[i]);
                  }
              }
          }
      }
      void PrintReestrAll(DirItem Item, DirActionItem Action)
      {
        /*if ((String)Action.Tag=="Raspor")
        {
          SaveFileDialog dlg = new SaveFileDialog();
          dlg.FileName = "Реестр распоряжений на "+DateTime.Now.ToShortDateString();
          dlg.Filter = "Microsoft Excel 2007|*.xlsx";
          dlg.FilterIndex = 1;
          dlg.RestoreDirectory = true ;          
          if (dlg.ShowDialog() == DialogResult.OK) 
            m_List.ExportListXMLX(dlg.FileName);
        }
        else if ((String)Action.Tag=="RasporProtokol")
        {
        }*/
      }
      void AddAuto(DirItem Item, DirActionItem Action)
      {
      	var form = new Forms.AutoJournal(m_engine);
      	form.ShowDialog();
      }
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
          Visible=true;
          OnOpen += OpenReestr;
          //OnPrint += PrintReestr;
          m_engine = engine;
          m_InitWheres=Wheres;          
          setData(0, "IconLarge", Properties.Resources.Auto);
          setData(0, "IconSmall", Properties.Resources.Auto);          
          var ExportAction = new DirActionItem(Properties.Resources.Auto,"Добавить заявку",AddAuto,null);
          setData(0,"Action",new List<DirItem.DirActionItem>(){ExportAction});
            
          
          //Filter();
      }
      public DirReestrAuto(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine, null);
      }
      public DirReestrAuto(Engine engine,String Caption,String ToolTip, Dictionary<String,Object> Wheres )
          : base(Caption, ToolTip)
      {
          Init(engine, Wheres);
      }
  }
  class DirFIO : DirItem
  {
      Engine m_engine;
      DirItem newItem;
      DirItem  printItem;
      /*public override bool IsDir() { return false; }
      public override bool IsParamPanel() { return false; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.LargeIcon; }
      Dictionary<String, Object> m_Wheres;*/
      void Open(DirItem Item)
      {
          Int32 ID = (Int32)Item.getData(0, "ID");
          var F = new Forms.RasporForm(m_engine, ID);
          F.ShowDialog();
      }
      /*
      public override void Filter()
      {

          m_List.clearWhere();
          foreach (String Pole in m_Params.getParams())
              m_List.setWhere(Pole, m_Params.getPole(Pole));
          if (m_Wheres != null)
              foreach (var Wheres in m_Wheres)
                  m_List.setWhere(Wheres.Key, Wheres.Value);
          m_List.Filter();
          //m_Params.setPole("NumPage", (m_List.FullLines - 1) / (Int32)m_Params.getPole("LineInPage") + 1);
          Int32 Num = m_List.NumLines;
          Clear();
          for (int i = 0; i < Num; i++)
          {
              Region.IPList.Line line = m_List.getLine(i);
              DirItem R = new DirItem();
              R.setData(0, "Caption", "Индивидуальный предпринематель" );
              R.setData(0, "ID", line.OGRN);
              R.setData(1, "Caption", line.INN);
              R.setData(2, "Caption", line.OGRN);
              R.setData(3, "Caption", line.FIO);
              R.OnOpen += Open;
              Add(R);
          }

      }
      /**/
     // public override DirItemParam getParams() { return m_Params; }
      //public override Int32 getCountColumn() { return 5; }
      /*public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "ИНН";
                  case 2: return "ОГРН";
                  case 3: return "ФИО";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                 
                  default: return 100;
              }
          return null;
      }
      void OpenReestr(DirItem Item)
      {
          Filter();
      }*/
      void FIOLogin(Engine engine)
      {
        Visible = engine.FIOAccess;
        newItem.Visible = true;
        printItem.Visible = true;
        Refresh();
      }
      void Init(Engine engine)
      {
        engine.OnFIOLogin += FIOLogin; 
        Visible = engine.FIOAccess;
        //OnOpen += OpenReestr;
        //OnPrint += PrintReestr;
        m_engine = engine;
        setData(0, "Caption", "Персональные данные");
        setData(0, "IconLarge", Properties.Resources.FIO);
        setData(0, "IconSmall", Properties.Resources.FIO);
        newItem = new DirItem("Обезличить");
        newItem.Visible = engine.FIOAccess;
        newItem.OnOpen+=(Item)=>
        {
          var form = new Forms.FIOForm(m_engine);
          form.ShowDialog();
        };
        printItem = new DirItem("Распечатать карточку");
        printItem.Visible = engine.FIOAccess;
        printItem.OnOpen+=(Item)=>
        {
          String ID = Forms.InputDialog.Input("Укажите идентификатор","Печать карточки","");
          if (ID!="")
          {
            var form = new Forms.FIOForm(m_engine,ID);
            form.ShowDialog();
          }
        };
        Add(newItem);
        Add(printItem);
      }
      public DirFIO(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine);
      }
  }
  class DirReestrIP : DirItem
  {
      Engine m_engine;
      IPList m_List;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return true; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void Open(DirItem Item)
      {
          Int32 ID = (Int32)Item.getData(0, "ID");
          var F = new Forms.RasporForm(m_engine, ID);
          F.ShowDialog();
      }
      public override void Filter()
      {

          m_List.clearWhere();
          foreach (String Pole in m_Params.getParams())
              m_List.setWhere(Pole, m_Params.getPole(Pole));
          if (m_Wheres != null)
              foreach (var Wheres in m_Wheres)
                  m_List.setWhere(Wheres.Key, Wheres.Value);
          m_List.Filter();
          //m_Params.setPole("NumPage", (m_List.FullLines - 1) / (Int32)m_Params.getPole("LineInPage") + 1);
          Int32 Num = m_List.NumLines;
          Clear();
          for (int i = 0; i < Num; i++)
          {
              Region.IPList.Line line = m_List.getLine(i);
              DirItem R = new DirItem();
              R.setData(0, "Caption", "Индивидуальный предпринематель" );
              R.setData(0, "ID", line.OGRN);
              R.setData(1, "Caption", line.INN);
              R.setData(2, "Caption", line.OGRN);
              R.setData(3, "Caption", line.FIO);
              R.OnOpen += Open;
              Add(R);
          }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 5; }
      public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "ИНН";
                  case 2: return "ОГРН";
                  case 3: return "ФИО";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                 
                  default: return 100;
              }
          return null;
      }
      void OpenReestr(DirItem Item)
      {
          Filter();
      }
      void PDnLogin(Engine engine)
      {
        Visible = engine.PDnAccess;
        Refresh();
      }
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
        engine.OnPDnLogin += PDnLogin; 
          Visible = engine.PDnAccess;
          OnOpen += OpenReestr;
          //OnPrint += PrintReestr;
          m_engine = engine;
          setData(0, "IconLarge", Properties.Resources.IPList);
          setData(0, "IconSmall", Properties.Resources.IPList);
          var ExportAction = new DirActionItem(Properties.Resources.Excel, "Экспортировать", null, null);
          ExportAction.SubItems = new List<DirItem.DirActionItem>();
          /*ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel, "Реестр распоряжений в XLSX", PrintReestrAll, "Raspor"));
          ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel, "Реестр распоряжений с протоколами в XLSX", PrintReestrAll, "RasporProtokol"));
          */setData(0, "Action", new List<DirItem.DirActionItem>() { ExportAction });

          m_List = new IPList(m_engine);
      /*    m_Params.addParams("RasporNumStart", EPoleType.Int32);
          m_Params.setPole("RasporNumStart", 0);
          m_Params.setCaption("RasporNumStart", "Начиная с номера:");


          m_Params.addParams("RasporNumEnd", EPoleType.Int32);
          m_Params.setPole("RasporNumEnd", 0);
          m_Params.setCaption("RasporNumEnd", "Оканчивая номером:");
          m_Params.addParams("RasporYear", EPoleType.Int32);
          m_Params.setPole("RasporYear", DateTime.Now.Year);
          m_Params.setCaption("RasporYear", "Год:");

          m_Params.addParams("IspUserID", EPoleType.Int32);
          m_Params.setPole("IspUserID", 0);
          m_Params.setEditor("IspUserID", "ComboBox");*/


          /*m_Params.addParams("AktDateStart", EPoleType.RegionDate);
          m_Params.setPole("AktDateStart",null);          
          m_Params.addParams("AktDateEnd", EPoleType.RegionDate);
          m_Params.setPole("AktDateEnd",null);*/


          /*var IspList = m_List.IspUserList(18);
          IspList[0] = "[Любой]";
          IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
          m_Params.setExProccessor("IspUserID", IspList);
          m_Params.setCaption("IspUserID", "Исполнитель");
          m_Params.addParams("ParentOtdelID", EPoleType.Int32);
          m_Params.setPole("ParentOtdelID", m_engine.CurrentUser.OtdelID);
          m_Params.setEditor("ParentOtdelID", "TreeComboBox");
          m_Params.setExProccessor("ParentOtdelID", m_engine.OtdelsForTree);
          m_Params.setCaption("ParentOtdelID", "Отдел:");*/

          m_Params.addParams("INN", EPoleType.String);
          m_Params.setPole("INN", "");
          m_Params.setCaption("INN", "ИНН");

          m_Params.addParams("Page", EPoleType.Int32);
          m_Params.setPole("Page", 1);
          m_Params.setEditor("Page", "SelectPage");
          m_Params.setCaption("Page", null);
          
          m_Params.addParams("NumPage", EPoleType.Int32);
          m_Params.setPole("NumPage", 1);
          m_Params.setEditor("NumPage", "");
          m_Params.setCaption("NumPage", null);
          m_Params.setExProccessor("Page", new Dictionary<String, String>() { { "Page", "Page" } });
          m_Params.addParams("LineInPage", EPoleType.Int32);
          m_Params.setPole("LineInPage", 20);
          m_Params.setCaption("LineInPage", "Выводить по:");

          if (Wheres != null)
          {
              m_Wheres = new Dictionary<String, Object>(Wheres);
              String[] P = m_Params.getParams();
              for (Int32 i = 0; i < P.Length; i++)
              {
                  if (m_Wheres.ContainsKey(P[i]))
                  {
                      m_Params.setPole(P[i], m_Wheres[P[i]]);
                      m_Wheres.Remove(P[i]);
                  }
              }
          }
          //Filter();
      }
      public DirReestrIP(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine, null);
      }
      public DirReestrIP(Engine engine, String Caption, String ToolTip, Dictionary<String, Object> Wheres)
          : base(Caption, ToolTip)
      {
          Init(engine, Wheres);
      }
  }
  class DirReestrKont : DirItem
  {
    Engine m_engine;
    Dictionary<String, Object> m_InitWheres;
    KontList m_List;
    DirItemParam m_Params = new DirItemParam();
    public override bool IsDir() { return true; }
    public override bool IsParamPanel() { return true; }
    public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
    Dictionary<String, Object> m_Wheres;
    void OpenKont(DirItem Item)
    {
        Int32 KontID = (Int32)Item.getData(0, "ID");
        KontForm RF = new KontForm(m_engine, KontID);
        RF.ShowDialog();
    }
    public override void Filter()
    {
        m_List.clearWhere();
        foreach (String Pole in m_Params.getParams())
            m_List.setWhere(Pole, m_Params.getPole(Pole));
        if (m_Wheres != null)
            foreach (var Wheres in m_Wheres)
                m_List.setWhere(Wheres.Key, Wheres.Value);

        m_List.Filter();
        m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
        Int32 Num = m_List.NumLines;
        Clear();
        for (int i = 0; i < Num; i++)
        {
            Region.KontListLine line = m_List.getLine(i);
            DirItem R = new DirItem();
            R.setData(0, "Caption", "№" + line.KontID.ToString());
            R.setData(0, "ID", line.KontID);
            R.setData(1, "Caption", line.INN.ToString());
            R.setData(2, "Caption", line.OGRN.ToString());
            R.setData(3, "Caption", line.KontName);
            //R.setData(4, "Caption", line.KontName);
            R.OnOpen += OpenKont;
            Add(R);
        }

    }
    public override DirItemParam getParams() { return m_Params; }
    public override Int32 getCountColumn() { return 4; }
    public override Object getColumn(Int32 N, String Role)
    {
        if (Role == "Caption")
            switch (N)
            {
                case 0: return "";
                case 1: return "ИНН";
                case 2: return "ОГРН";
                case 3: return "Наименование";
                //case 4: return "Наименование";
                default: return null;
            }
        if (Role == "Width")
            switch (N)
            {
                case 0: return 0;
                case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                //case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                default: return 100;
            }
        return null;
    }
    void OpenReestr(DirItem Item)
    {
      WhereSetup();
      Filter();
    }
    void WhereSetup()
    {
      if (m_List!=null) return;
      m_List = new KontList(m_engine);
      m_Params.addParams("Page", EPoleType.Int32);
      m_Params.setPole("Page", 1);            
      m_Params.setEditor("Page", "SelectPage");
      m_Params.setCaption("Page", null);
      m_Params.addParams("NumPage", EPoleType.Int32);                        
      m_Params.setPole("NumPage", 1);
      m_Params.setEditor("NumPage", "");
      m_Params.setCaption("NumPage", null);
      m_Params.setExProccessor("Page", new Dictionary<String,String>(){{"Page","Page"}});
      m_Params.addParams("LineInPage", EPoleType.Int32);
      m_Params.setPole("LineInPage", 20);
      m_Params.setCaption("LineInPage", "Выводить по:");

      m_Params.addParams("MyKont", EPoleType.Bool);                        
      m_Params.setPole("MyKont", false);
      m_Params.setCaption("MyKont", "Мои контрагенты");
      
      m_Params.addParams("Find", EPoleType.String);
      m_Params.setPole("Find", "");
      m_Params.setCaption("Find", "Cтрока поиска(Наименоваие, ИНН, ОГРН):");

      

/*        m_Params.addParams("ProcurorNumStart", EPoleType.Int32);
      m_Params.setPole("ProcurorNumStart", 0);
      m_Params.setCaption("ProcurorNumStart", "Начиная с номера:");
      m_Params.addParams("ProcurorNumEnd", EPoleType.Int32);
      m_Params.setPole("ProcurorNumEnd", 0);
      m_Params.setCaption("ProcurorNumEnd", "Оканчивая номером:");
      m_Params.addParams("ProcurorYear", EPoleType.Int32);
      m_Params.setPole("ProcurorYear", DateTime.Now.Year);
      m_Params.setCaption("ProcurorYear", "Год:");
      m_Params.addParams("IspUserID", EPoleType.Int32);
      m_Params.setPole("IspUserID", m_engine.CurrentUser.UserID);
      m_Params.setEditor("IspUserID", "ComboBox");
      var IspList = m_ProcurorList.IspUserList(18);
      IspList[0] = "[Любой]";
      IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
      m_Params.setExProccessor("IspUserID", IspList);
      m_Params.setCaption("IspUserID", "Исполнитель");
      m_Params.addParams("OtdelID", EPoleType.Int32);
      m_Params.setPole("OtdelID", m_engine.CurrentUser.OtdelID);
      m_Params.setEditor("OtdelID", "TreeComboBox");
      m_Params.setExProccessor("OtdelID", m_engine.OtdelsForTree);
      m_Params.setCaption("OtdelID", "Отдел:");*/
      if (m_InitWheres != null)
      {
          m_Wheres = new Dictionary<String, Object>(m_InitWheres);
          String[] P = m_Params.getParams();
          for (Int32 i = 0; i < P.Length; i++)
          {
              if (m_Wheres.ContainsKey(P[i]))
              {
                  m_Params.setPole(P[i], m_Wheres[P[i]]);
                  m_Wheres.Remove(P[i]);
              }
          }

      }
    }
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
        OnOpen += OpenReestr;
        m_engine = engine;
        m_InitWheres = Wheres; 
        setData(0, "IconLarge", Properties.Resources.Organization);
        setData(0, "IconSmall", Properties.Resources.Organization);  
      }
      public DirReestrKont(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine, null);
      }
      public DirReestrKont(Engine engine, String Caption, String ToolTip, Dictionary<String, Object> Wheres)
          : base(Caption, ToolTip)
      {
          Init(engine, Wheres);
      }
  }
  class DirKont : DirItem
  {
      Engine m_engine;
      public override bool IsDir() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.LargeIcon; }

      void NewKont(DirItem Item)
      {
          //MessageBox.Show("Новое!");
      }
      void ReestrKont(DirItem Item)
      {
      }
      void ReestrKont2(DirItem Item)
      {
          /*RegionRasporListForm F = new RegionRasporListForm(m_engine);
          //this.Visible = false;
          F.ShowDialog();
          F = null;
          //this.Visible = true;*/
      }
      public DirKont(Engine engine)
          : base("Реестр контрагентов", "")
      {
          m_engine = engine;
          setData(0, "IconLarge", Properties.Resources.Dir);
          setData(0, "IconSmall", Properties.Resources.Dir);
          DirItem New = new DirItem("Новый", "Ввод нового контрагента");
          New.setData(0, "IconLarge", Properties.Resources.New);
          New.setData(0, "IconSmall", Properties.Resources.New);
          New.OnOpen += NewKont;
          Add(New);
          DirItem Reestr = new DirReestrKont(m_engine, "Реестр контрагентов", "");
          Reestr.OnOpen += ReestrKont;
          Reestr.setData(0, "IconLarge", Properties.Resources.List);
          Reestr.setData(0, "IconSmall", Properties.Resources.List);
          Add(Reestr);

          /*DirItem Reestr2 = new DirItem("Реестр2", "Реестр распоряжений");
          Reestr2.OnOpen += ReestrRaspor2;
          Reestr2.setData(0, "IconLarge", Properties.Resources.Dir);
          Reestr2.setData(0, "IconSmall", Properties.Resources.Dir);
          Add(Reestr2);*/

      }
  }
  class DirReestrPoruch : DirItem
  {
      Engine m_engine;
      PoruchList m_List;
      Dictionary<String, Object> m_InitWheres;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return true; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void Open(DirItem Item)
      {
        var ID = (Int32)Item.getData(0, "ID");
        var F = new Forms.PoruchForm(m_engine, ID);
        F.ShowDialog();
      }
      public override void Filter()
      {

        m_List.clearWhere();
        foreach (String Pole in m_Params.getParams())
          m_List.setWhere(Pole, m_Params.getPole(Pole));
        if (m_Wheres!=null)
          foreach (var Wheres in m_Wheres)
            m_List.setWhere(Wheres.Key, Wheres.Value);
        m_Wheres = null;
        m_List.Filter();
        m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
        Int32 Num = m_List.NumLines;
        setData(0,"FullNumItem",m_List.FullLines);
        Clear();
        for (int i = 0; i < Num; i++)
        {
          Region.PoruchListLine line = m_List.getLine(i);
          var R = new DirItem();
          R.setData(0, "Caption", "Поручение №" + line.PoruchID.ToString());
          R.setData(0, "ID", line.PoruchID);
          R.setData(0, "Type", "Poruch");
          R.setData(1, "Caption", line.PoruchID.ToString());
          R.setData(2, "Caption", line.IspFIO);
          R.setData(3, "Caption", m_engine.getOtdel(line.OtdelID).OtdelName);
          R.OnOpen += Open;
          Add(R);
        }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 4; }
      public override Object getColumn(Int32 N, String Role)
      {
        if (Role == "Caption")
          switch (N)
          {
            case 0: return "";
            case 1: return "№";
            case 2: return "Исполнитель";
            case 3: return "Отдел";
            default: return null;
          }
        if (Role == "Width")
          switch (N)
          {
            case 0: return 0;
            case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            default: return 100;
          }
        return null;
      }
      void OpenReestr(DirItem Item)
      {
        WhereSetup();
        Filter();
      }
      void WhereSetup()
      {
        if (m_List!=null) return;
        m_List = new PoruchList(m_engine);
          
        // Подготовка доп. данных для фильтров
        /*var IspList = m_List.IspUserList(18);
        IspList[0] = "[Любой]";
        IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
        var RasporList = new Dictionary<Int32,String>(m_engine.UserFIO);
        RasporList[0] = "[Любой]";
        RasporList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;*/
        // Добавление фильтров
        var userList = new UserList(m_engine);
        userList.setWhere("MinCountPoruch",1);// В списке исполнителей выводить только тех укого хотябы одно распоряжение
        var IspUserID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Editor","UserSelector"},{"Ex",userList},{"Caption","Исполнитель:"},{"Pr",-970}};
        var ParentOtdelID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",m_engine.CurrentUser.OtdelID},{"Editor","TreeComboBox"},{"Ex",m_engine.OtdelsForTree},{"Caption","Отдел:"},{"Pr",-960}};
        m_Params.addParams("IspUserID", IspUserID);
        m_Params.addParams("ParentOtdelID", ParentOtdelID);
     
        // Настрока дополнительных фильтров
        var AddFilter = new Dictionary<String, Dictionary<String, Object>>();
        AddFilter.Add("IspUserID", IspUserID);
        AddFilter.Add("ParentOtdelID", ParentOtdelID);        
        /*var PolesDate = new Dictionary<String, String>(){{"Date","Распоряжение"}, {"Start","Дата начала"}, {"End","Дата окончания"}, {"FStart","Фак. дата нач."}, {"FEnd","Фак. окон."}, {"AktDate","Дата акта"}, {"PredpisDate","Дата предписания"}, {"ControlDate","Дата кон. пред."}, {"Online","Внесение в онлайн"}};
        foreach(var i in PolesDate)
        {
          AddFilter[i.Key+"Start"] = new Dictionary<String,Object>(){{"Type",EPoleType.RegionDate},{"Value",new RegionDate()},{"Editor","Date"},{"Caption",i.Value+" с:"}};
          AddFilter[i.Key+"End"] = new Dictionary<String,Object>(){{"Type",EPoleType.RegionDate},{"Value",new RegionDate()},{"Editor","Date"},{"Caption",i.Value+" по:"}}; 
        }
        m_Params.addParams("AddFilter", new Dictionary<String,Object>(){{"Type",EPoleType.String},{"Value",""},{"Editor","FilterManager"},{"Caption","Доп. условия"},{"Ex",AddFilter},{"Pr",1000}});*/
        // Настройка перелистывания по страницам
        var Page = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor","SelectPage"},{"Ex",new Dictionary<String,String>(){{"Page","Page"}}},{"Caption",null},{"Pr",900}};
        var NumPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor",""},{"Caption",null},{"Pr",900}};
        var LineInPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",20},{"Caption","Выводить по:"},{"Pr",900}};
        m_Params.addParams("Page", Page);
        m_Params.addParams("NumPage", NumPage);
        m_Params.addParams("LineInPage", LineInPage);
        
        if (m_InitWheres != null)
        {
          m_Wheres = new Dictionary<String, Object>(m_InitWheres);
          String[] P = m_Params.getParams();
          foreach(var where in m_Wheres)
          {
            /*if (!m_Params.isParam(where.Key))
              if (AddFilter.ContainsKey(where.Key))
                m_Params.addParams(where.Key, AddFilter[where.Key]);*/
            if (m_Params.isParam(where.Key))
              m_Params.setPole(where.Key, where.Value);
          }
        }
      }
      void PrintReestrAll(DirItem Item, DirActionItem Action)
      {
        if ((String)Action.Tag=="Raspor")
        {
          var dlg = new SaveFileDialog();
          dlg.FileName = "Реестр распоряжений на "+DateTime.Now.ToShortDateString();
          dlg.Filter = "Microsoft Excel 2007|*.xlsx";
          dlg.FilterIndex = 1;
          dlg.RestoreDirectory = true ;          
          if (dlg.ShowDialog() == DialogResult.OK)
          {
            m_List.ExportListXMLX_Task(dlg.FileName);
            new Forms.TaskWait(m_engine).ShowDialog();
          }
        }
        else if ((String)Action.Tag=="RasporProtokol")
        {
        }
      }
      void PrintReestr(DirItem Item)
      {
      }
      
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
        OnOpen += OpenReestr;
        //OnPrint += PrintReestr;
        m_engine = engine;   
        m_InitWheres = Wheres;         
        setData(0, "IconLarge", Properties.Resources.Raspor);
        setData(0, "IconSmall", Properties.Resources.Raspor);          
        var ExportAction = new DirActionItem(Properties.Resources.Excel,"Экспортировать",null,null);
        ExportAction.SubItems = new List<DirItem.DirActionItem>();
        ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр Поручений в XLSX",PrintReestrAll,"Poruch"));
        //ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений с протоколами в XLSX",PrintReestrAll,"RasporProtokol"));
        setData(0,"Action",new List<DirItem.DirActionItem>(){ExportAction});
      }
      public DirReestrPoruch(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
        Init(engine, null);
      }
      public DirReestrPoruch(Engine engine,String Caption,String ToolTip, Dictionary<String,Object> Wheres )
          : base(Caption, ToolTip)
      {
        Init(engine, Wheres);
      }
  }
  class DirReestrPred : DirItem
  {
      Engine m_engine;
      PredList m_List;
      Dictionary<String, Object> m_InitWheres;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return true; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void OpenPred(DirItem Item)
      {
          Int32 PredID = (Int32)Item.getData(0, "ID");
          var PF = new Forms.PredForm(m_engine, PredID);
          PF.ShowDialog();
      }
      public override void Filter()
      {

          m_List.clearWhere();
          foreach (String Pole in m_Params.getParams())
              m_List.setWhere(Pole, m_Params.getPole(Pole));
          if (m_Wheres!=null)
              foreach (var Wheres in m_Wheres)
                  m_List.setWhere(Wheres.Key, Wheres.Value);
          m_List.Filter();
          m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
          Int32 Num = m_List.NumLines;
          Clear();
          for (int i = 0; i < Num; i++)
          {
              Region.PredList.Line line = m_List.getLine(i);
              DirItem R = new DirItem();
              R.setData(0, "Caption", "Предписание ФБУЗ №" + line.PredNum.ToString() + " от " + line.PredDate.ToShortDateString());
              R.setData(0, "ID", line.PredID);
              R.setData(1, "Caption", line.PredNum.ToString());
              R.setData(2, "Caption", line.PredDate.ToShortDateString());
              R.setData(3, "Caption", line.IspFIO);
              R.setData(4, "Caption", line.KontName);
              R.OnOpen += OpenPred;
              Add(R);
          }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 5; }
      public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "№";
                  case 2: return "от";
                  case 3: return "Исполнитель";
                  case 4: return "Наименование";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  default: return 100;
              }
          return null;
      }
      void OpenReestr(DirItem Item)
      {
        WhereSetup();
        Filter();
      }
      void WhereSetup()
      {
        if (m_List!=null) return;
        m_List = new PredList(m_engine);
        m_Params.addParams("PredNumStart", EPoleType.Int32);
        m_Params.setPole("PredNumStart", 0);
        m_Params.setCaption("PredNumStart", "Начиная с номера:");
        
        
        m_Params.addParams("PredNumEnd", EPoleType.Int32);
        m_Params.setPole("PredNumEnd", 0);
        m_Params.setCaption("PredNumEnd", "Оканчивая номером:");
        m_Params.addParams("PredYear", EPoleType.Int32);
        m_Params.setPole("PredYear", DateTime.Now.Year);
        m_Params.setCaption("PredYear", "Год:");
        
        m_Params.addParams("IspUserID", EPoleType.Int32);
        m_Params.setPole("IspUserID",0);
        m_Params.setEditor("IspUserID", "UserSelector");
        var userList = new UserList(m_engine);
        userList.setWhere("MinCountPred",1);// В списке исполнителей выводить только тех укого хотябы одно распоряжение
        m_Params.setExProccessor("IspUserID", userList);

        
        /*m_Params.addParams("AktDateStart", EPoleType.RegionDate);
        m_Params.setPole("AktDateStart",null);          
        m_Params.addParams("AktDateEnd", EPoleType.RegionDate);
        m_Params.setPole("AktDateEnd",null);*/
        
        
        /*var IspList = m_List.IspUserList(18);
        IspList[0] = "[Любой]";
        IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
        m_Params.setExProccessor("IspUserID", IspList);*/
        m_Params.setCaption("IspUserID", "Исполнитель");
        m_Params.addParams("ParentOtdelID", EPoleType.Int32);
        m_Params.setPole("ParentOtdelID", m_engine.CurrentUser.OtdelID);
        m_Params.setEditor("ParentOtdelID", "TreeComboBox");
        m_Params.setExProccessor("ParentOtdelID", m_engine.OtdelsForTree);
        m_Params.setCaption("ParentOtdelID", "Отдел:");

        m_Params.addParams("Page", EPoleType.Int32);
        m_Params.setPole("Page", 1);            
        m_Params.setEditor("Page", "SelectPage");
        m_Params.setCaption("Page", null);
        m_Params.addParams("NumPage", EPoleType.Int32);                        
        m_Params.setPole("NumPage", 1);
        m_Params.setEditor("NumPage", "");
        m_Params.setCaption("NumPage", null);
        m_Params.setExProccessor("Page", new Dictionary<String,String>(){{"Page","Page"}});
        m_Params.addParams("LineInPage", EPoleType.Int32);
        m_Params.setPole("LineInPage", 20);
        m_Params.setCaption("LineInPage", "Выводить по:");
        
        if (m_InitWheres != null)
        {
            m_Wheres = new Dictionary<String, Object>(m_InitWheres);
            String[] P = m_Params.getParams();
            for (Int32 i = 0; i < P.Length; i++)
            {
                if (m_Wheres.ContainsKey(P[i]))
                {
                    m_Params.setPole(P[i], m_Wheres[P[i]]);
                    m_Wheres.Remove(P[i]);
                }
            }
        }
      }
      void PrintReestrAll(DirItem Item, DirActionItem Action)
      {
        if ((String)Action.Tag=="Raspor")
        {
          SaveFileDialog dlg = new SaveFileDialog();
          dlg.FileName = "Реестр распоряжений на "+DateTime.Now.ToShortDateString();
          dlg.Filter = "Microsoft Excel 2007|*.xlsx";
          dlg.FilterIndex = 1;
          dlg.RestoreDirectory = true ;          
          if (dlg.ShowDialog() == DialogResult.OK) 
            m_List.ExportListXMLX(dlg.FileName);
        }
        else if ((String)Action.Tag=="RasporProtokol")
        {
        }
      }
      void PrintReestr(DirItem Item)
      {
      }
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
        Visible = true;
        OnOpen += OpenReestr;
        //OnPrint += PrintReestr;
        m_engine = engine;   
        m_InitWheres = Wheres;          
        setData(0, "IconLarge", Properties.Resources.Raspor);
        setData(0, "IconSmall", Properties.Resources.Raspor);          
        var ExportAction = new DirActionItem(Properties.Resources.Excel,"Экспортировать",null,null);
        ExportAction.SubItems = new List<DirItem.DirActionItem>();
        ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений в XLSX",PrintReestrAll,"Raspor"));
        ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений с протоколами в XLSX",PrintReestrAll,"RasporProtokol"));
        setData(0,"Action",new List<DirItem.DirActionItem>(){ExportAction});
      }
      public DirReestrPred(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine, null);
      }
      public DirReestrPred(Engine engine,String Caption,String ToolTip, Dictionary<String,Object> Wheres )
          : base(Caption, ToolTip)
      {
          Init(engine, Wheres);
      }
  }
  class DirReestrProcuror : DirItem
  {
      Engine m_engine;
      ProcurorList m_ProcurorList;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return true; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void OpenProcuror(DirItem Item)
      {
          Int32 ProcurorID = (Int32)Item.getData(0, "ID");
          var RF = new Forms.ProcurorForm(m_engine, ProcurorID);
          RF.ShowDialog();
      }
      public override void Filter()
      {

          m_ProcurorList.clearWhere();
          foreach (String Pole in m_Params.getParams())
              m_ProcurorList.setWhere(Pole, m_Params.getPole(Pole));
          if (m_Wheres != null)
              foreach (var Wheres in m_Wheres)
                  m_ProcurorList.setWhere(Wheres.Key, Wheres.Value);

          m_ProcurorList.Filter();
          Int32 Num = m_ProcurorList.NumLines;
          Clear();
          for (int i = 0; i < Num; i++)
          {
              Region.ProcurorList.Line line = m_ProcurorList.getLine(i);
              DirItem R = new DirItem();
              R.setData(0, "Caption", "№" + line.ProcurorNum.ToString() + " от " + line.Start.ToShortDateString());
              R.setData(0, "ID", line.ProcurorID);
              R.setData(1, "Caption", line.ProcurorNum.ToString());
              R.setData(2, "Caption", line.Start.ToShortDateString());
              R.setData(3, "Caption", line.IspFIO);
              //R.setData(4, "Caption", line.KontName);
              R.OnOpen += OpenProcuror;
              Add(R);
          }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 4; }
      public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "№";
                  case 2: return "от";
                  case 3: return "Исполнитель";
                  //case 4: return "Наименование";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  //case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  default: return 100;
              }
          return null;
      }
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {        	
          m_engine = engine;
          Visible = m_engine.isAccess("ProcurorEdit");
          m_ProcurorList = new ProcurorList(m_engine);
          m_Params.addParams("ProcurorNumStart", EPoleType.Int32);
          m_Params.setPole("ProcurorNumStart", 0);
          m_Params.setCaption("ProcurorNumStart", "Начиная с номера:");
          m_Params.addParams("ProcurorNumEnd", EPoleType.Int32);
          m_Params.setPole("ProcurorNumEnd", 0);
          m_Params.setCaption("ProcurorNumEnd", "Оканчивая номером:");
          m_Params.addParams("LineInPage", EPoleType.Int32);
          m_Params.setPole("LineInPage", 20);
          m_Params.setCaption("LineInPage", "Выводить по:");
          m_Params.addParams("ProcurorYear", EPoleType.Int32);
          m_Params.setPole("ProcurorYear", DateTime.Now.Year);
          m_Params.setCaption("ProcurorYear", "Год:");
          m_Params.addParams("IspUserID", EPoleType.Int32);
          //m_Params.setPole("IspUserID", m_engine.CurrentUser.UserID);
          m_Params.setEditor("IspUserID", "ComboBox");
          var IspList = m_ProcurorList.IspUserList(18);
          IspList[0] = "[Любой]";
          IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
          m_Params.setExProccessor("IspUserID", IspList);
          m_Params.setCaption("IspUserID", "Исполнитель");
          m_Params.addParams("OtdelID", EPoleType.Int32);
          m_Params.setPole("OtdelID", m_engine.CurrentUser.OtdelID);
          m_Params.setEditor("OtdelID", "TreeComboBox");
          m_Params.setExProccessor("OtdelID", m_engine.OtdelsForTree);
          m_Params.setCaption("OtdelID", "Отдел:");
          if (Wheres != null)
          {
              m_Wheres = new Dictionary<String, Object>(Wheres);
              String[] P = m_Params.getParams();
              for (Int32 i = 0; i < P.Length; i++)
              {
                  if (m_Wheres.ContainsKey(P[i]))
                  {
                      m_Params.setPole(P[i], m_Wheres[P[i]]);
                      m_Wheres.Remove(P[i]);
                  }
              }

          }

          Filter();
      }
      public DirReestrProcuror(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine, null);
      }
      public DirReestrProcuror(Engine engine, String Caption, String ToolTip, Dictionary<String, Object> Wheres)
          : base(Caption, ToolTip)
      {
          Init(engine, Wheres);
      }
  }
  class DirProcuror : DirItem
  {
      Engine m_engine;
      public override bool IsDir() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.LargeIcon; }

      void NewProcuror(DirItem Item)
      {
          //MessageBox.Show("Новое!");
      }
      void ReestrProcuror(DirItem Item)
      {
      }
      void ReestrProcuror2(DirItem Item)
      {
          RegionRasporListForm F = new RegionRasporListForm(m_engine);
          //this.Visible = false;
          F.ShowDialog();
          F = null;
          //this.Visible = true;
      }
      public DirProcuror(Engine engine)
          : base("Проверки прокуратуры", "")
      {
          m_engine = engine;
          setData(0, "IconLarge", Properties.Resources.Dir);
          setData(0, "IconSmall", Properties.Resources.Dir);
          DirItem New = new DirItem("Новая", "Ввод новой прокуроской проверки");
          New.setData(0, "IconLarge", Properties.Resources.New);
          New.setData(0, "IconSmall", Properties.Resources.New);
          New.OnOpen += NewProcuror;
          Add(New);
          DirItem Reestr = new DirReestrProcuror(m_engine, "Реестр проверок прокуратуры", "");
          Reestr.OnOpen += ReestrProcuror;
          Reestr.setData(0, "IconLarge", Properties.Resources.List);
          Reestr.setData(0, "IconSmall", Properties.Resources.List);
          Add(Reestr);

          /*DirItem Reestr2 = new DirItem("Реестр2", "Реестр распоряжений");
          Reestr2.OnOpen += ReestrRaspor2;
          Reestr2.setData(0, "IconLarge", Properties.Resources.Dir);
          Reestr2.setData(0, "IconSmall", Properties.Resources.Dir);
          Add(Reestr2);*/

      }
  }
  class DirReestrProtokol : DirItem
  {
    Engine m_engine;
    ProtokolList m_List;
    readonly DirItemParam m_Params = new DirItemParam(); // Список параметров
    Dictionary<String, Object> m_Wheres;// Указанные условия
    public override bool IsDir() { return true; }
    public override bool IsParamPanel() { return true; }
    public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
    void Open(DirItem Item)
    {
          var ID = (Int32)Item.getData(0, "ID");
          var F = new Forms.ProtokolForm(m_engine, ID);
          F.ShowDialog();
    }
    public override void Filter()
    {

        m_List.clearWhere();
        foreach (String Pole in m_Params.getParams())
            m_List.setWhere(Pole, m_Params.getPole(Pole));
        if (m_Wheres!=null)
            foreach (var Wheres in m_Wheres)
                m_List.setWhere(Wheres.Key, Wheres.Value);
        m_List.Filter();
        m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
        Int32 Num = m_List.NumLines;
        Clear();
        Dictionary<Int32,String> Article = m_engine.Article;
        for (int i = 0; i < Num; i++)
        {
            Region.ProtokolList.Line line = m_List.getLine(i);
            var R = new DirItem();
            R.setData(0, "Caption", "Протокол №" + line.ProtokolNum.ToString() + " от " + line.ProtokolReg.ToShortDateString());
            R.setData(0, "ID", line.ProtokolID);
            R.setData(1, "Caption", line.ProtokolNum.ToString());
            R.setData(2, "Caption", line.ProtokolReg.ToShortDateString());
            R.setData(3, "Caption", line.ProtokolFIO);
            R.setData(4, "Caption", Article[line.ArticleID]);
            R.OnOpen += Open;
            Add(R);
        }

    }
    public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 5; }
      public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "№";
                  case 2: return "от";
                  case 3: return "Составил";
                  case 4: return "Статья";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  default: return 100;
              }
          return null;
      }
    void OpenReestr(DirItem Item)
    {
      Filter();
    }
    void PrintReestrAll(DirItem Item, DirActionItem Action)
    {
      if ((String)Action.Tag=="Protokol")
      {
        var dlg = new SaveFileDialog();
        dlg.FileName = "Реестр протоколов на "+DateTime.Now.ToShortDateString();
        dlg.Filter = "Microsoft Excel 2007|*.xlsx";
        dlg.FilterIndex = 1;
        dlg.RestoreDirectory = true ;          
        if (dlg.ShowDialog() == DialogResult.OK)
        {
          m_List.ExportListXMLX_Task(dlg.FileName);
          new Forms.TaskWait(m_engine).ShowDialog();
        }
      }
    }
    void Init(Engine engine, Dictionary<String, Object> Wheres)
    {
      Visible = true;
      OnOpen += OpenReestr;
      m_engine = engine;         
      m_List = new ProtokolList(m_engine);
      setData(0, "IconLarge", Properties.Resources.Protokol);
      setData(0, "IconSmall", Properties.Resources.Protokol);       
      // Настройка меню      
      var ExportAction = new DirActionItem(Properties.Resources.Excel,"Экспортировать",null,null);
      ExportAction.SubItems = new List<DirItem.DirActionItem>();
      ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр протоколов в XLSX",PrintReestrAll,"Protokol"));
      setData(0,"Action",new List<DirItem.DirActionItem>(){ExportAction});
      var IspUser = new Dictionary<Int32,String>(m_engine.UserFIO);

      //OIDList[18] = m_engine.getOtdel(18);
      //Настройка фильтров
      var ProtokolYear = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",DateTime.Now.Year},{"Caption","Год:"},{"Pr",-1000}};
      var OID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",m_engine.CurrentUser.Otdel.OID},{"Editor","ComboBox"},{"Ex",m_engine.OID},{"Caption","Отдел:"},{"Pr",-960}};
      var ProtokolIspUserID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Editor","ComboBox"},{"Ex",IspUser},{"Caption","Исполнитель:"},{"Pr",-920}};
      var FindText = new Dictionary<String,Object>(){{"Type",EPoleType.String},{"Value",""},{"Editor","TextBox"},{"Caption","Поиск:"},{"Pr",-900}};
      var ProtokolNumStart = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Caption","Номер с:"},{"Pr",-880}};
      var ProtokolNumEnd = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Caption","Номер по:"},{"Pr",-840}};
      var ArticleID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Editor","ComboBox"},{"Ex",m_engine.Article},{"Caption","Статья:"},{"Pr",-920}};
      m_Params.addParams("ProtokolYear", ProtokolYear);
      m_Params.addParams("OID", OID);
      m_Params.addParams("ProtokolIspUserID", ProtokolIspUserID);
      m_Params.addParams("ProtokolNumStart", ProtokolNumStart);
      m_Params.addParams("ProtokolNumEnd", ProtokolNumEnd);
      m_Params.addParams("FindText", FindText);
      m_Params.addParams("ArticleID", ArticleID);
      
      
      // Настройка перелистывания по страницам
      var Page = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor","SelectPage"},{"Ex",new Dictionary<String,String>(){{"Page","Page"}}},{"Caption",null},{"Pr",900}};
      var NumPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor",""},{"Caption",null},{"Pr",900}};
      var LineInPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",20},{"Caption","Выводить по:"},{"Pr",900}};
      m_Params.addParams("Page", Page);
      m_Params.addParams("NumPage", NumPage);
      m_Params.addParams("LineInPage", LineInPage);
      if (Wheres != null)
      {
          m_Wheres = new Dictionary<String, Object>(Wheres);
          String[] P = m_Params.getParams();
          for (Int32 i = 0; i < P.Length; i++)
          {
              if (m_Wheres.ContainsKey(P[i]))
              {
                  m_Params.setPole(P[i], m_Wheres[P[i]]);
                  m_Wheres.Remove(P[i]);
              }
          }
      }
      
      /*
      m_engine = engine;
      //m_List = new RasporList(m_engine);      
      m_Params.addParams("ProtokolNumStart", EPoleType.Int32);
      m_Params.setPole("ProtokolNumStart", 0);
      m_Params.setCaption("ProtokolNumStart", "Начиная с номера:");            
      m_Params.addParams("ProtokolNumEnd", EPoleType.Int32);
      m_Params.setPole("ProtokolNumEnd", 0);
      m_Params.setCaption("RasporNumEnd", "Оканчивая номером:");
      
      m_Params.addParams("LineInPage", EPoleType.Int32);
      m_Params.setPole("LineInPage", 20);
      m_Params.setCaption("LineInPage", "Выводить по:");
      
      m_Params.addParams("ProtokolYear", EPoleType.Int32);
      m_Params.setPole("ProtokolYear", DateTime.Now.Year);
      m_Params.setCaption("ProtokolYear", "Год:");
      
      m_Params.addParams("ProtokolIspUserID", EPoleType.Int32);
      m_Params.setPole("ProtokolIspUserID", m_engine.CurrentUser.UserID);
      m_Params.setEditor("ProtokolIspUserID", "ComboBox");
      var IspList = m_List.IspUserList(18);
      IspList[0] = "[Любой]";
      IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
      m_Params.setExProccessor("ProtokolIspUserID", IspList);
      m_Params.setCaption("ProtokolIspUserID", "Составил протокол");
      
      if (Wheres != null)
      {
          m_Wheres = new Dictionary<String, Object>(Wheres);
          String[] P = m_Params.getParams();
          for (Int32 i = 0; i < P.Length; i++)
          {
              if (m_Wheres.ContainsKey(P[i]))
              {
                  m_Params.setPole(P[i], m_Wheres[P[i]]);
                  m_Wheres.Remove(P[i]);
              }
          }

      }   

      Filter();*/
    }   
    public DirReestrProtokol(Engine engine, String Caption, String ToolTip)
            : base(Caption, ToolTip)
    {
      Init(engine, null);
    }
    public DirReestrProtokol(Engine engine, String Caption, String ToolTip, Dictionary<String, Object> Wheres)
            : base(Caption, ToolTip)
    {
       Init(engine, Wheres);
    }
  }
  class DirProtokol : DirItem
  {
      readonly Engine m_engine;
      public override bool IsDir() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.LargeIcon; }

      void NewProtokol(DirItem Item)
      {
          //MessageBox.Show("Новое!");
      }
      void ReestrProtokol(DirItem Item)
      {
      
      }
      public DirProtokol(Engine engine)
          : base("Протоколы", "Ввод/Реестр административных протоколов")
      {
        Visible = false;
          m_engine = engine;
          base.setData(0, "IconLarge", Properties.Resources.Dir);
          base.setData(0, "IconSmall", Properties.Resources.Dir);
          var New = new DirItem("Новый", "Ввод нового протокола");
          New.setData(0, "IconLarge", Properties.Resources.New);
          New.setData(0, "IconSmall", Properties.Resources.New);
          New.OnOpen += NewProtokol;
          Add(New);
          var Reestr = new DirItem("Реестры протоколов", "Реестры протоколов по территориальным отделам");
          //Reestr.OnOpen += ReestrProtokol;
          Reestr.setData(0, "IconLarge", Properties.Resources.List);
          Reestr.setData(0, "IconSmall", Properties.Resources.List);
          Add(Reestr);
          var ReestrAll = new DirReestrProtokol(m_engine, "Все протоколы", "Реестр протоколов отдела", null);
          ReestrAll.setData(0, "IconLarge", Properties.Resources.List);
          ReestrAll.setData(0, "IconSmall", Properties.Resources.List);
          Reestr.Add(ReestrAll);

          foreach(var Otdel in m_engine.Otdels)
            if (Otdel.Value.TO==1)
          {
            DirItem ReestrN = new DirReestrProtokol(m_engine, Otdel.Value.OtdelName, "Реестр протоколов отдела", new Dictionary<String, Object>() {{"OID",Otdel.Value.OtdelID} });
            ReestrN.setData(0, "IconLarge", Properties.Resources.List);
            ReestrN.setData(0, "IconSmall", Properties.Resources.List);
            Reestr.Add(ReestrN);
            
          }
          //DirItem Reestr = new DirReestrProtokol(m_engine, "Реестр протоколов", "");

/*            DirItem Reestr13 = new DirReestrProtokol(m_engine, "Управление", "Реестр протоколов управления", new Dictionary<String, Object>() {{"OID",13} });
          Reestr13.setData(0, "IconLarge", Properties.Resources.Dir);
          Reestr13.setData(0, "IconSmall", Properties.Resources.Dir);
          Reestr.Add(Reestr13);

          DirItem Reestr19 = new DirReestrProtokol(m_engine, "ТО в Ванинском районе", "Реестр протоколов территориального отдела Управления Федеральной службы по надзору в сфере защиты прав потребителей и благополучия человека по Хабаровскому краю в Верхнебуреинском районе", new Dictionary<String, Object>() { { "OID", 13 } });
          Reestr19.setData(0, "IconLarge", Properties.Resources.Dir);
          Reestr19.setData(0, "IconSmall", Properties.Resources.Dir);
          Reestr.Add(Reestr19);

          DirItem Reestr17 = new DirReestrProtokol(m_engine, "ТО в Верхнебуреинском районе", "Реестр протоколов территориального отдела Управления Федеральной службы по надзору сфере защиты прав потребителей и благополучия человека по Хабаровскому краю в Вяземском, Бикинском, имени Лазо районах", new Dictionary<String, Object>() { { "OID", 17 } });
          Reestr17.setData(0, "IconLarge", Properties.Resources.Dir);
          Reestr17.setData(0, "IconSmall", Properties.Resources.Dir);
          Reestr.Add(Reestr17);                
          DirItem Reestr17 = new DirReestrProtokol(m_engine, "ТО в г. Верхнебуреинском районе", "Реестр протоколов территориального отдела Управления Федеральной службы по надзору сфере защиты прав потребителей и благополучия человека по Хабаровскому краю в Вяземском, Бикинском, имени Лазо районах", new Dictionary<String, Object>() { { "OID", 17 } });
          Reestr17.setData(0, "IconLarge", Properties.Resources.Dir);
          Reestr17.setData(0, "IconSmall", Properties.Resources.Dir);
          Reestr.Add(Reestr17);  */              

          // Не окончено
          
      }
  }
  class DirReestrRaspor : DirItem
  {
      Engine m_engine;
      RasporList m_List;
      Dictionary<String, Object> m_InitWheres;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return true; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void Open(DirItem Item)
      {
        var ID = (Int32)Item.getData(0, "ID");
        var F = new Forms.RasporForm(m_engine, ID);
        F.ShowDialog();
      }
      public override void Filter()
      {

        m_List.clearWhere();
        foreach (String Pole in m_Params.getParams())
          m_List.setWhere(Pole, m_Params.getPole(Pole));
        if (m_Wheres!=null)
          foreach (var Wheres in m_Wheres)
            m_List.setWhere(Wheres.Key, Wheres.Value);
        m_Wheres = null;
        m_List.Filter();
        m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
        Int32 Num = m_List.NumLines;
        setData(0,"FullNumItem",m_List.FullLines);
        Clear();
        for (int i = 0; i < Num; i++)
        {
          Region.RasporListLine line = m_List.getLine(i);
          var R = new DirItem();
          R.setData(0, "Caption", "Распоряжение №" + line.RasporNum.ToString() + " от " + line.Date.ToShortDateString());
          R.setData(0, "ID", line.RasporID);
          R.setData(0, "Type", "Raspor");
          R.setData(1, "Caption", line.RasporNum.ToString());
          R.setData(2, "Caption", line.Date.ToShortDateString());
          R.setData(3, "Caption", line.IspFIO);
          R.setData(4, "Caption", line.KontName);
          R.OnOpen += Open;
          Add(R);
        }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 5; }
      public override Object getColumn(Int32 N, String Role)
      {
        if (Role == "Caption")
          switch (N)
          {
            case 0: return "";
            case 1: return "№";
            case 2: return "от";
            case 3: return "Исполнитель";
            case 4: return "Наименование";
            default: return null;
          }
        if (Role == "Width")
          switch (N)
          {
            case 0: return 0;
            case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
            default: return 100;
          }
        return null;
      }
      void newRaspor(DirItem Item,DirActionItem Action)
      {
        Int32 RasporID = m_engine.newRaspor(0);
        Raspor raspor = m_engine.getRaspor(RasporID);
        raspor.showEditor();
        WhereSetup();
        Filter();
      }
      void OpenReestr(DirItem Item)
      {
        WhereSetup();
        Filter();
      }
      void WhereSetup()
      {
        if (m_List!=null) return;
        m_List = new RasporList(m_engine);
          
        // Подготовка доп. данных для фильтров
        /*var IspList = m_List.IspUserList(18);
        IspList[0] = "[Любой]";
        IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;
        var RasporList = new Dictionary<Int32,String>(m_engine.UserFIO);
        RasporList[0] = "[Любой]";
        RasporList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;*/
        // Добавление фильтров
        var userList = new UserList(m_engine);
        userList.setWhere("MinCountRaspor",1);// В списке исполнителей выводить только тех укого хотябы одно распоряжение
        var userList2 = new UserList(m_engine);
        userList2.setWhere("MinCountWorkRaspor",1);// В списке исполнителей выводить только тех укого хотябы одно распоряжение
        var RasporYear = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",DateTime.Now.Year},{"Caption","Год:"},{"Pr",-1000}};
        var RasporNumStart = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Caption","Начиная с номера:"},{"Pr",-990}};
        var RasporNumEnd = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Caption","Оканчивая номером:"},{"Pr",-980}};
        var IspUserID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Editor","UserSelector"},{"Ex",userList},{"Caption","Исполнитель:"},{"Pr",-970}};
        var RasporUserID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Editor","UserSelector"},{"Ex",userList2},{"Caption","Участник:"},{"Pr",-970}};
        var ParentOtdelID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",m_engine.CurrentUser.OtdelID},{"Editor","OtdelSelector"},{"Ex",null},{"Caption","Отдел:"},{"Pr",-960}};
        m_Params.addParams("RasporYear", RasporYear);
        m_Params.addParams("RasporNumStart", RasporNumStart);
        m_Params.addParams("RasporNumEnd", RasporNumEnd);
        m_Params.addParams("IspUserID", IspUserID);
      
        if ((m_InitWheres != null) && m_InitWheres.ContainsKey("RasporUserID")) 
          m_Params.addParams("RasporUserID", RasporUserID);
        m_Params.addParams("ParentOtdelID", ParentOtdelID);
     
        // Настрока дополнительных фильтров
        var AddFilter = new Dictionary<String, Dictionary<String, Object>>();
        AddFilter.Add("RasporYear", RasporYear);
        AddFilter.Add("RasporNumStart", RasporNumStart);
        AddFilter.Add("RasporNumEnd", RasporNumEnd);
        AddFilter.Add("IspUserID", IspUserID);
        AddFilter.Add("RasporUserID", RasporUserID);
        AddFilter.Add("ParentOtdelID", ParentOtdelID);
        
        var PolesDate = new Dictionary<String, String>(){{"Date","Распоряжение"}, {"Start","Дата начала"}, {"End","Дата окончания"}, {"FStart","Фак. дата нач."}, {"FEnd","Фак. окон."}, {"AktDate","Дата акта"}, {"PredpisDate","Дата предписания"}, {"ControlDate","Дата кон. пред."}, {"Online","Внесение в онлайн"}};
        foreach(var i in PolesDate)
        {
          AddFilter[i.Key+"Start"] = new Dictionary<String,Object>(){{"Type",EPoleType.RegionDate},{"Value",new RegionDate()},{"Editor","Date"},{"Caption",i.Value+" с:"}};
          AddFilter[i.Key+"End"] = new Dictionary<String,Object>(){{"Type",EPoleType.RegionDate},{"Value",new RegionDate()},{"Editor","Date"},{"Caption",i.Value+" по:"}}; 
        }
        m_Params.addParams("AddFilter", new Dictionary<String,Object>(){{"Type",EPoleType.String},{"Value",""},{"Editor","FilterManager"},{"Caption","Доп. условия"},{"Ex",AddFilter},{"Pr",1000}});
        // Настройка перелистывания по страницам
        var Page = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor","SelectPage"},{"Ex",new Dictionary<String,String>(){{"Page","Page"}}},{"Caption",null},{"Pr",900}};
        var NumPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor",""},{"Caption",null},{"Pr",900}};
        var LineInPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",20},{"Caption","Выводить по:"},{"Pr",900}};
        m_Params.addParams("Page", Page);
        m_Params.addParams("NumPage", NumPage);
        m_Params.addParams("LineInPage", LineInPage);
        
        if (m_InitWheres != null)
        {
          m_Wheres = new Dictionary<String, Object>(m_InitWheres);
          String[] P = m_Params.getParams();
          foreach(var where in m_Wheres)
          {
            /*if (!m_Params.isParam(where.Key))
              if (AddFilter.ContainsKey(where.Key))
                m_Params.addParams(where.Key, AddFilter[where.Key]);*/
            if (m_Params.isParam(where.Key))
              m_Params.setPole(where.Key, where.Value);
          }
        }
      }
      void PrintReestrAll(DirItem Item, DirActionItem Action)
      {
        if ((String)Action.Tag=="Raspor")
        {
          var dlg = new SaveFileDialog();
          dlg.FileName = "Реестр распоряжений на "+DateTime.Now.ToShortDateString();
          dlg.Filter = "Microsoft Excel 2007|*.xlsx";
          dlg.FilterIndex = 1;
          dlg.RestoreDirectory = true ;          
          if (dlg.ShowDialog() == DialogResult.OK)
          {
            m_List.ExportListXMLX_Task(dlg.FileName);
            new Forms.TaskWait(m_engine).ShowDialog();
          }
        }
        else if ((String)Action.Tag=="RasporProtokol")
        {
        }
      }
      void PrintReestrAllPilot(DirItem Item, DirActionItem Action)
      {
        if ((String)Action.Tag=="Raspor")
        {
          var dlg = new SaveFileDialog();
          dlg.FileName = "Реестр распоряжений на "+DateTime.Now.ToShortDateString();
          dlg.Filter = "Microsoft Excel 2007|*.xlsx";
          dlg.FilterIndex = 1;
          dlg.RestoreDirectory = true ;          
          if (dlg.ShowDialog() == DialogResult.OK)
          {
            m_List.ExportListXMLXPilot_Task(dlg.FileName);
            new Forms.TaskWait(m_engine).ShowDialog();
          }
        }
        else if ((String)Action.Tag=="RasporProtokol")
        {
        }
      }
      void PrintReestr(DirItem Item)
      {
      }
      
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
        OnOpen += OpenReestr;
        //OnPrint += PrintReestr;
        m_engine = engine;   
        m_InitWheres = Wheres;         
        setData(0, "IconLarge", Properties.Resources.Raspor);
        setData(0, "IconSmall", Properties.Resources.Raspor);          
        var ExportAction = new DirActionItem(Properties.Resources.Excel,"Экспортировать",null,null);
        ExportAction.SubItems = new List<DirItem.DirActionItem>();
        ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений в XLSX",PrintReestrAll,"Raspor"));
        ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Сформировать реест для пилотного проекта в XLSX",PrintReestrAllPilot,"Raspor"));
        //ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений с протоколами в XLSX",PrintReestrAll,"RasporProtokol"));
        var NewAction = new DirActionItem(Properties.Resources.Doc,"Новое рапоряжение",this.newRaspor,"Raspor");
        setData(0,"Action",new List<DirItem.DirActionItem>(){ExportAction,NewAction});
      }
      public DirReestrRaspor(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
        Init(engine, null);
      }
      public DirReestrRaspor(Engine engine,String Caption,String ToolTip, Dictionary<String,Object> Wheres )
          : base(Caption, ToolTip)
      {
        Init(engine, Wheres);
      }
  }
  class DirReestrReport : DirItem
  {
      Engine m_engine;
      ReportList m_List;
      DirItemParam m_Params = new DirItemParam();
      public override bool IsDir() { return true; }
      public override bool IsParamPanel() { return true; }
      public override System.Windows.Forms.View ViewDir() { return System.Windows.Forms.View.Details; }
      Dictionary<String, Object> m_Wheres;
      void Open(DirItem Item)
      {
          Int32 ID = (Int32)Item.getData(0, "ID");
          /*var F = new Forms.RasporForm(m_engine, ID);
          F.ShowDialog();*/
      }
      public override void Filter()
      {

          m_List.clearWhere();
          foreach (String Pole in m_Params.getParams())
              m_List.setWhere(Pole, m_Params.getPole(Pole));
          if (m_Wheres!=null)
              foreach (var Wheres in m_Wheres)
                  m_List.setWhere(Wheres.Key, Wheres.Value);
          m_List.Filter();
          m_Params.setPole("NumPage",(m_List.FullLines-1)/(Int32)m_Params.getPole("LineInPage")+1);
          Int32 Num = m_List.NumLines;
          Clear();
          Dictionary<Int32,String> ReportTemplate = m_engine.ReportTemplate;
          for (int i = 0; i < Num; i++)
          {
              Region.ReportList.Line line = m_List.getLine(i);
              DirItem R = new DirItem();
              R.setData(0, "Caption", "Отчёт №" + line.ReportID.ToString() + " от " + line.Date.ToShortDateString());
              R.setData(0, "ID", line.ReportID);
              R.setData(0, "Action", new List<DirItem.DirActionItem>(){new DirActionItem(Properties.Resources.Play, "Пересчитать отчёт",ProcessReport,null)});
              R.setData(1, "Caption", line.ReportID.ToString());
              R.setData(2, "Caption", line.Date.ToShortDateString());
              R.setData(3, "Caption", line.Start.ToShortDateString());
              R.setData(4, "Caption", line.End.ToShortDateString());
              R.setData(5, "Caption", ReportTemplate[line.ReportTemplateID]);
              R.OnOpen += Open;
              Add(R);
          }

      }
      public override DirItemParam getParams() { return m_Params; }
      public override Int32 getCountColumn() { return 6; }
      public override Object getColumn(Int32 N, String Role)
      {
          if (Role == "Caption")
              switch (N)
              {
                  case 0: return "";
                  case 1: return "№";
                  case 2: return "от";
                  case 3: return "Начало";
                  case 4: return "Окончание";
                  case 5: return "Наименование";
                  default: return null;
              }
          if (Role == "Width")
              switch (N)
              {
                  case 0: return 0;
                  case 1: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 2: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 3: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 4: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  case 5: return System.Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent;
                  default: return 100;
              }
          return null;
      }
      void ProcessReport(DirItem Item, DirActionItem Action)
      {
        Int32 ReportID = (Int32)Item.getData(0,"ID");
        m_engine.getReport(ReportID).Process_task();
        m_engine.ShowTask();
      }
      void OpenReestr(DirItem Item)
      {
        Filter();
      }
      void PrintReestrAll(DirItem Item, DirActionItem Action)
      {
      /*  if ((String)Action.Tag=="Raspor")
        {
          SaveFileDialog dlg = new SaveFileDialog();
          dlg.FileName = "Реестр распоряжений на "+DateTime.Now.ToShortDateString();
          dlg.Filter = "Microsoft Excel 2007|*.xlsx";
          dlg.FilterIndex = 1;
          dlg.RestoreDirectory = true ;          
          if (dlg.ShowDialog() == DialogResult.OK)
          {
            m_List.ExportListXMLX_Task(dlg.FileName);
            new Forms.TaskWait(m_engine).ShowDialog();
          }
        }
        else if ((String)Action.Tag=="RasporProtokol")
        {
        }*/
      }
      void PrintReestr(DirItem Item)
      {
      }
      void Init(Engine engine, Dictionary<String, Object> Wheres)
      {
          OnOpen += OpenReestr;
          //OnPrint += PrintReestr;
          m_engine = engine;         
/*          setData(0, "IconLarge", Properties.Resources.Raspor);
          setData(0, "IconSmall", Properties.Resources.Raspor);*/          
          var ExportAction = new DirActionItem(Properties.Resources.Excel, "Экспортировать",null,null);
          
          ExportAction.SubItems = new List<DirItem.DirActionItem>();
          ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений в XLSX",PrintReestrAll,"Raspor"));
          //ExportAction.SubItems.Add(new DirActionItem(Properties.Resources.Excel,"Реестр распоряжений с протоколами в XLSX",PrintReestrAll,"RasporProtokol"));
          setData(0,"Action",new List<DirItem.DirActionItem>(){ExportAction});
          m_List = new ReportList(m_engine);
          
          // Подготовка доп. данных для фильтров
          /*var IspList = m_List.IspUserList(18);
          IspList[0] = "[Любой]";
          IspList[m_engine.CurrentUser.UserID] = m_engine.CurrentUser.FIO;/**/
          
          // Добавление фильтров
          var ParentOtdelID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",m_engine.CurrentUser.Otdel.OID},{"Editor","TreeComboBox"},{"Ex",m_engine.OtdelsForTree},{"Caption","Отдел:"},{"Pr",-960}};
          m_Params.addParams("ParentOtdelID", ParentOtdelID);
          /*var RasporYear = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",DateTime.Now.Year},{"Caption","Год:"},{"Pr",-1000}};
          var RasporNumStart = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Caption","Начиная с номера:"},{"Pr",-990}};
          var RasporNumEnd = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Caption","Оканчивая номером:"},{"Pr",-980}};
          var IspUserID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",0},{"Editor","ComboBox"},{"Ex",IspList},{"Caption","Исполнитель:"},{"Pr",-970}};
          var ParentOtdelID = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",m_engine.CurrentUser.OtdelID},{"Editor","TreeComboBox"},{"Ex",m_engine.OtdelsForTree},{"Caption","Отдел:"},{"Pr",-960}};
          m_Params.addParams("RasporYear", RasporYear);
          m_Params.addParams("RasporNumStart", RasporNumStart);
          m_Params.addParams("RasporNumEnd", RasporNumEnd);
          m_Params.addParams("IspUserID", IspUserID);
          m_Params.addParams("ParentOtdelID", ParentOtdelID);/**/
       
          // Настрока дополнительных фильтров
          var AddFilter = new Dictionary<String, Dictionary<String, Object>>();
          /*AddFilter.Add("RasporYear", RasporYear);
          AddFilter.Add("RasporNumStart", RasporNumStart);
          AddFilter.Add("RasporNumEnd", RasporNumEnd);
          AddFilter.Add("IspUserID", IspUserID);/**/
          AddFilter.Add("ParentOtdelID", ParentOtdelID);
          var PolesDate = new Dictionary<String, String>(){{"Date","Распоряжение"}, {"Start","Дата начала"}, {"End","Дата окончания"}};
          foreach(var i in PolesDate)
          {
            AddFilter[i.Key+"Start"] = new Dictionary<String,Object>(){{"Type",EPoleType.RegionDate},{"Value",new RegionDate()},{"Editor","Date"},{"Caption",i.Value+" с:"}};
            AddFilter[i.Key+"End"] = new Dictionary<String,Object>(){{"Type",EPoleType.RegionDate},{"Value",new RegionDate()},{"Editor","Date"},{"Caption",i.Value+" по:"}}; 
          }
          m_Params.addParams("AddFilter", new Dictionary<String,Object>(){{"Type",EPoleType.String},{"Value",""},{"Editor","FilterManager"},{"Caption","Доп. условия"},{"Ex",AddFilter},{"Pr",1000}});
          // Настройка перелистывания по страницам
          var Page = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor","SelectPage"},{"Ex",new Dictionary<String,String>(){{"Page","Page"}}},{"Caption",null},{"Pr",900}};
          var NumPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",1},{"Editor",""},{"Caption",null},{"Pr",900}};
          var LineInPage = new Dictionary<String,Object>(){{"Type",EPoleType.Int32},{"Value",20},{"Caption","Выводить по:"},{"Pr",900}};
          m_Params.addParams("Page", Page);
          m_Params.addParams("NumPage", NumPage);
          m_Params.addParams("LineInPage", LineInPage);
          
          if (Wheres != null)
          {
              m_Wheres = new Dictionary<String, Object>(Wheres);
              String[] P = m_Params.getParams();
              for (Int32 i = 0; i < P.Length; i++)
              {
                  if (m_Wheres.ContainsKey(P[i]))
                  {
                      m_Params.setPole(P[i], m_Wheres[P[i]]);
                      m_Wheres.Remove(P[i]);
                  }
              }
          }
      }
      public DirReestrReport(Engine engine, String Caption, String ToolTip)
          : base(Caption, ToolTip)
      {
          Init(engine, null);
      }
      public DirReestrReport(Engine engine,String Caption,String ToolTip, Dictionary<String,Object> Wheres )
          : base(Caption, ToolTip)
      {
          Init(engine, Wheres);
      }
  }  
}
